<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Blog extends CI_Controller {

	function __construct()
    {
        parent::__construct();
		$this->load->model("Blog_model");
		$this->load->model('Cate_model');
    }
	
	public function index()
	{
		$this->load->library('pagination');
		$this->load->helper('common');
		//获取分类
		$data['cates'] = $this->Cate_model->getAll();
		
		$data['blogs'] = $this->Blog_model->getAll();
		$this->load->view('blog',$data);
	}
	
	public function blogadd()
	{
		
		if(IS_POST)
		{
			$this->Blog_model->add();
			redirect("blog/index");
		}else
		{
			$data['cates'] = $this->Cate_model->getAll();
			$this->load->view('blogadd', $data);
		}
	}
	
	public function blogedit()
	{
		if(IS_POST)
		{
			$this->Blog_model->edit();
			redirect("blog/index");
		}else
		{
			$data['id'] = $this->uri->segment(4);
			$data['cates'] = $this->Cate_model->getAll();
			$data['blog'] = $this->Blog_model->getOne($data['id']);
			$this->load->view('blogedit',$data);
		}
		
	}
	
	public function del()
	{
		$this->Blog_model->del();
		redirect("blog/index");
	}
	
	
}
